package com.session03;

public class Triangle extends Polygon {
    //全局变量
    public int base;
    public int height;

    public Triangle(int base, int height) {
        //调用父类的构造器，需要使用super
        super(3);
        this.base = base;
        this.height = height;
        System.out.println("在Triangle类的构造器中");
    }

    @Override
    public String toString() {
        return "三角形的底为 " + this.base + "三角形的高为 " + this.height;
    }

    public double getArea() {
        return (double) (this.base * this.height) / 2;
    }
}
